/*
 * Copyright (c) 2010-2011, okazoh_tk. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *  - Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *  - Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *  - Neither the name of the copyright holder nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef ALKES_SAMPLE_01_SAMPLE_H_INCLUDED_
#define ALKES_SAMPLE_01_SAMPLE_H_INCLUDED_

//#define VALIDATE_FILTER

#if 0
#include "alkes/win32app/DirectXAppTraits.h"
typedef alkes::IGraphics3D ApplicationTarget;
#if !defined(VALIDATE_FILTER)
typedef alkes::DirectXAppTraits ApplicationTraits;
#endif
#else
#include "alkes/win32app/WGLAppTraits.h"
typedef alkes::IGraphics3D ApplicationTarget;
#if !defined(VALIDATE_FILTER)
typedef alkes::WGLAppTraits ApplicationTraits;
#endif
#endif

#if defined(VALIDATE_FILTER)
#include "alkes/gfxfilter.h"
template<class T>
class FilterAppTraits
{
public:
    typedef alkes::GfxFilterGraphics GraphicsType;
    typedef alkes::Screen3D ScreenType;

    template<class W>
    static GraphicsType* createGraphics(W* window)
    {
        GraphicsType* g = GraphicsType::create(T::create(window->getHWND()));

        g->disableAllLogFilter();

        alkes::LogFilter filters[] = {
#if 0
            alkes::AL_FILTER_IRenderTarget2DpushMatrix,
            alkes::AL_FILTER_IRenderTarget2DpopMatrix,
            alkes::AL_FILTER_IRenderTarget2Dtranslate,
            alkes::AL_FILTER_IRenderTarget2Dscale,
            alkes::AL_FILTER_IRenderTarget2Drotate,
            alkes::AL_FILTER_IRenderTarget2DskewX,
            alkes::AL_FILTER_IRenderTarget2DskewY,
            alkes::AL_FILTER_IRenderTarget3Dtranslate,
            alkes::AL_FILTER_IRenderTarget3Dscale,
            alkes::AL_FILTER_IRenderTarget3Drotate,
#else
            alkes::AL_FILTER_IRenderTarget2DdrawShape,
#endif
        };
        int i;
        for (i = 0; i < sizeof(filters)/sizeof(filters[0]); ++i)
        {
            g->enableLogFilter(filters[i]);
        }
        return g;
    }
};

typedef FilterAppTraits<ApplicationTarget> ApplicationTraits;
#endif



#include "RectangleContents.h"
#include "LineContents.h"
#include "ImageContents.h"
#include "TransformContents.h"
#include "PolylineContents.h"

class Menu;

class Sample
    : public alkes::Application<ApplicationTraits>
{
public:
    Sample(const char* title);
    virtual ~Sample();

protected:
    virtual bool onCreate();
    virtual void onDestroy();
    virtual void onResize(uint16_t w, uint16_t h);
    virtual void onMouseMove(uint16_t x, uint16_t y);
    virtual void onLButtonDown();

private:
    alkes::Layer* debug_layer_;
    alkes::Layer* menu_layer_;
    alkes::Layer* contents_layer_;
    uint16_t mouse_x_, mouse_y_;
    Menu* menu_;
    alkes::Scene* current_contents_;

    alkes::intrusive_ptr<alkes::ImageBuffer> image_;
    alkes::intrusive_ptr<alkes::ImageBuffer> mask_image_;
};

#endif
